package com.augurit.common.system.convert;

import java.util.ArrayList;
import java.util.List;

import com.augurit.common.entity.AcPartyRole;
import com.augurit.common.entity.AcRole;
import com.augurit.common.entity.AcRoleFunc;
import com.augurit.common.entity.AcUserRole;
import com.augurit.common.system.web.org.form.AcPartyRoleForm;
import com.augurit.common.system.web.org.form.AcRoleForm;
import com.augurit.common.system.web.org.form.AcRoleFuncForm;
import com.augurit.common.system.web.org.form.AcUserRoleForm;

public class AcRoleConverter {

	public static AcRoleForm convertToForm(AcRole entity){
		if(entity != null){
			AcRoleForm form = new AcRoleForm();
			
			form.setRoleId(entity.getRoleId());
			form.setRoleCode(entity.getRoleCode());
			form.setRoleName(entity.getRoleName());
			form.setRoleGroup(entity.getRoleGroup());
			form.setRoleType(entity.getRoleType());
			form.setSortNo(entity.getSortNo());
			form.setRemark(entity.getRemark());
			
			return form;
		}
		else
			return null;
	}
	
	
	public static List<AcRoleForm> convertToFormList(List<AcRole> list){
		if(list != null && list.size() > 0){
			List<AcRoleForm> result = new ArrayList();
			
			for(AcRole entity : list){
				result.add(convertToForm(entity));
			}
			
			return result;
		}else
			return null;
	}
	
	public static void convertToEntity(AcRoleForm form, AcRole entity){
		if(form != null && entity != null){

			if(form.getRoleId() != null)
				entity.setRoleId(form.getRoleId());
			
			if(form.getRoleCode() != null && form.getRoleCode().trim().length() > 0)
				entity.setRoleCode(form.getRoleCode());
			
			if(form.getRoleName() != null && form.getRoleName().trim().length() > 0)
				entity.setRoleName(form.getRoleName());
			
			if(form.getRoleGroup() != null && form.getRoleGroup().trim().length() > 0)
				entity.setRoleGroup(form.getRoleGroup());
			
			if(form.getRoleType() != null && form.getRoleType().trim().length() > 0)
				entity.setRoleType(form.getRoleType());
			
			if(form.getSortNo() != null)
				entity.setSortNo(form.getSortNo());
			
			if(form.getRemark() != null && form.getRemark().trim().length() > 0)
				entity.setRemark(form.getRemark());
		}
	}
	
	public static void convertToEntity(AcPartyRoleForm form, AcPartyRole entity){
		if(form != null && entity != null){

			if(form.getPrId() != null)
				entity.setPrId(form.getPrId());
			
			if(form.getPartyType() != null && form.getPartyType().trim().length() > 0)
				entity.setPartyType(form.getPartyType());
			
			if(form.getPartyId() != null)
				entity.setPartyId(form.getPartyId());
			
			if(form.getRoleId() != null)
				entity.setRoleId(form.getRoleId());
		}
	}
	
	public static void convertToEntity(AcRoleFuncForm form, AcRoleFunc entity){
		if(form != null && entity != null){

			if(form.getRfId() != null)
				entity.setRfId(form.getRfId());
			
			if(form.getRoleId() != null)
				entity.setRoleId(form.getRoleId());
			
			if(form.getFuncId() != null)
				entity.setFuncId(form.getFuncId());
			
			if(form.getModuleId() != null)
				entity.setModuleId(form.getModuleId());
			
			if(form.getAppId() != null)
				entity.setAppId(form.getAppId());
		}
	}
	
	public static void convertToEntity(AcUserRoleForm form, AcUserRole entity){
		if(form != null && entity != null){

			if(form.getUrId() != null)
				entity.setUrId(form.getUrId());
			
			if(form.getUserId() != null)
				entity.setUserId(form.getUserId());
			
			if(form.getRoleId() != null)
				entity.setRoleId(form.getRoleId());
			
			if(form.getAuth() != null && form.getAuth().trim().length() > 0)
				entity.setAuth(form.getAuth());
		}
	}
}
